package main

import (
	"fmt"
	"reflect"
)

func main() {
	type cat struct {
		Name string `json:"name"`
		Type int `json:"type" id:"100"`
	}

	ins := cat{
		Name: "mi",
		Type: 1,
	}

	typeOfCat := reflect.TypeOf(ins)

	/*
		反射得到 StructField
		再通过  StructField得到Tag的相关值

	 */
	for i := 0; i < typeOfCat.NumField(); i++ {
		field := typeOfCat.Field(i)
		fmt.Printf("name: %v tag: '%v'\n", field.Name, field.Tag)
	}


	if catType, ok := typeOfCat.FieldByName("Type"); ok {
		fmt.Println(catType.Tag.Get("json"), catType.Tag.Get("id"))
	}

}
